package com.imut.hcdp.service.impl;

import java.util.Date;
import java.util.List;

import com.imut.hcdp.domain.HcdpTrainSeat;
import com.imut.hcdp.mapper.HcdpTrainSeatMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.imut.hcdp.mapper.HcdpTrainMapper;
import com.imut.hcdp.domain.HcdpTrain;
import com.imut.hcdp.service.IHcdpTrainService;


@Service
public class HcdpTrainServiceImpl implements IHcdpTrainService
{
    @Autowired
    private HcdpTrainMapper hcdpTrainMapper;

    @Autowired
    private HcdpTrainSeatMapper hcdpTrainSeatMapper;


    @Override
    public HcdpTrain selectHcdpTrainById(Long id)
    {
        return hcdpTrainMapper.selectHcdpTrainById(id);
    }


    @Override
    public List<HcdpTrain> selectHcdpTrainList(HcdpTrain hcdpTrain)
    {
        return hcdpTrainMapper.selectHcdpTrainList(hcdpTrain);
    }


    @Override
    public int insertHcdpTrain(HcdpTrain hcdpTrain)
    {
        hcdpTrain.setCrttime(new Date());
        return hcdpTrainMapper.insertHcdpTrain(hcdpTrain);
    }


    @Override
    public int updateHcdpTrain(HcdpTrain hcdpTrain)
    {
        return hcdpTrainMapper.updateHcdpTrain(hcdpTrain);
    }


    @Override
    public int deleteHcdpTrainByIds(Long[] ids)
    {
        if(ids.length > 0){
            for (int i = 0; i < ids.length; i++) {
                hcdpTrainSeatMapper.deleteHcdpTrainSeatByTrainId(ids[i]);
            }
        }
        return hcdpTrainMapper.deleteHcdpTrainByIds(ids);
    }


    @Override
    public int deleteHcdpTrainById(Long id)
    {
        hcdpTrainSeatMapper.deleteHcdpTrainSeatByTrainId(id);
        return hcdpTrainMapper.deleteHcdpTrainById(id);
    }
}
